//
//  EmoticonCollectionViewCell.swift
//  EmotiDemo
//
//  Created by leador on 17/5/17.
//  Copyright © 2017年 袁满. All rights reserved.
//

import UIKit

class EmoticonCollectionViewCell: UICollectionViewCell {
    
    lazy var emoticonBtn : UIButton = UIButton()
    
    var emoticon : Emoticon? {
        
        didSet {
            
            guard let emoticon = emoticon else {
                return
            }
            
            
            emoticonBtn.setImage(UIImage(contentsOfFile: emoticon.pngPath ?? ""), for: .normal)
            emoticonBtn.setTitle(emoticon.emojiCode, for: .normal)
            
            if emoticon.isRemove {
                let deleteImagePath = Bundle.main.bundlePath + "/Emoticons.bundle/compose_emotion_delete"
                emoticonBtn.setImage(UIImage(contentsOfFile:deleteImagePath), for: .normal)
            }
            
            if emoticon.isEmpty {
                return
            }
            
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension EmoticonCollectionViewCell {
    
    func setupUI() {
        
        contentView.addSubview(emoticonBtn)
        
        emoticonBtn.isUserInteractionEnabled = false
        
        emoticonBtn.frame = contentView.bounds
        
        emoticonBtn.titleLabel?.font = UIFont.systemFont(ofSize: 32)
        
    }
    
}
